/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved. 
 */
package com.icinfo.cloud.provider.punish.fastcase.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.punish.fastcase.dto.CaseAppraiseFeedbackDto;
import com.icinfo.cloud.provider.punish.fastcase.dto.CaseAppraiseRecordByPartyQueryDto;
import com.icinfo.cloud.provider.punish.fastcase.dto.CaseAppraiseRecordByUserQueryDto;
import com.icinfo.cloud.provider.punish.fastcase.service.ICaseAppraiseRecordService;
import com.icinfo.cloud.provider.punish.fastcase.vo.CaseAppraiseDetailInfoVo;
import com.icinfo.cloud.provider.punish.fastcase.vo.CaseAppraiseRecordVo;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述: 案件评价记录表 case_appraise_record 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2023年02月02日
 */
@Slf4j
@RestController
@RequestMapping("/punish/fast/case/appraise")
public class CaseAppraiseRecordController extends BaseController {

    @Resource
    private ICaseAppraiseRecordService caseAppraiseRecordService;

    /**
     * 描述： 根据承办人查询案件评价记录(分页)
     *
     * @author: zhengqiang
     * @date: 2023/2/2
     * @param: queryDto
     * @return {@link Result< PageResponse< CaseAppraiseRecordVo>>}
     **/
    @PostMapping("/getCaseAppraiseRecordPageListByUser")
    public Result<PageResponse<CaseAppraiseRecordVo>> getCaseAppraiseRecordPageListByUser(@RequestBody @Validated CaseAppraiseRecordByUserQueryDto queryDto) {
        UserDTO userDTO = UserUtil.getUserInfo();
        if (ObjectUtils.isEmpty(userDTO)) {
            throw new BusinessException("登录失效");
        }
        queryDto.setUserId(userDTO.getUserId().toString());
        queryDto.setOrgCode(userDTO.getOrgCode());
        List<CaseAppraiseRecordVo> caseAppraiseRecordPageList = caseAppraiseRecordService.getCaseAppraiseRecordPageList(queryDto);
        return Result.success(Constant.STRING_GET_SUCCESS, new PageResponse<>(caseAppraiseRecordPageList));
    }

    /**
     * 描述： 根据当事人查询案件评价记录(分页)
     *
     * @author: zhengqiang
     * @date: 2023/2/2
     * @param: queryDto
     * @return {@link Result< PageResponse< CaseAppraiseRecordVo>>}
     **/
    @PostMapping("/getCaseAppraiseRecordPageListByParty")
    public Result<PageResponse<CaseAppraiseRecordVo>> getCaseAppraiseRecordPageListByParty(@RequestBody @Validated CaseAppraiseRecordByPartyQueryDto queryDto) {
        CaseAppraiseRecordByUserQueryDto userQueryDto = new CaseAppraiseRecordByUserQueryDto();
        BeanUtils.copyProperties(queryDto, userQueryDto);
        List<CaseAppraiseRecordVo> caseAppraiseRecordPageList = caseAppraiseRecordService.getCaseAppraiseRecordPageList(userQueryDto);
        return Result.success(Constant.STRING_GET_SUCCESS, new PageResponse<>(caseAppraiseRecordPageList));
    }

    /**
     * 描述： 根据案件id获取案件评价详情
     *
     * @author: zhengqiang
     * @date: 2023/2/3
     * @param: caseId
     * @return {@link Result< CaseAppraiseDetailInfoVo>}
     **/
    @GetMapping("/getCaseAppraiseRecordDetailByCaseId")
    public Result<CaseAppraiseDetailInfoVo> getCaseAppraiseRecordDetailByCaseId(@RequestParam String caseId) {
        CaseAppraiseDetailInfoVo caseAppraiseDetailInfoVo = caseAppraiseRecordService.getCaseAppraiseRecordDetailByCaseId(caseId);
        return Result.success(caseAppraiseDetailInfoVo);
    }

    /**
     * 描述： 更新评价反馈信息
     *
     * @author: zhengqiang
     * @date: 2023/2/6
     * @param: caseAppraiseFeedbackDto
     * @return {@link Result}
     **/
    @PostMapping("/updateCaseFeedback")
    public Result updateCaseFeedback(@RequestBody @Validated CaseAppraiseFeedbackDto caseAppraiseFeedbackDto) {
        return caseAppraiseRecordService.updateCaseFeedback(caseAppraiseFeedbackDto);
    }


}